home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-15 | 31.1 KB | 952 lines | [TEXT/KAHL] |
- /**
- --
- --
- -- App: Getting Started w/QD GX (WWDC)
- --
- --
- -- Version: 1.0 4/93: added all of the calls required to support the "Getting
- -- Started with QuickDraw™ GX" session at the WWDC '93
- --
- -- 8/93: updated file to work with the ß2 "GXified" interface files
- --
- -- 12/93: updated for b3. - dmh & pla
- -- 3/94: corrected usage of GXSetShapeAttributes. - dmh
- -- 8/94: universalized. - dmh
- --
- -- 4/96 bob Updated #includes to support changed GX Library names.
- -- Changed fixed to Fixed.
- -- Updated the note regarding the files needed to run.
- -- Updated the copyright date.
- --
- --
- -- File: Getting Started GX - shapes.c
- --
- -- Comments: This code demonstrates creates, manipulates, and draws all of the QuickDraw
- -- GX shapes used in this app. This is the same code which was used during the
- -- "Getting Started With QuickDraw GX" WWDC '93 session.
- --
- -- This application will also support multiple windows. We present two menus
- -- to the user to draw into the contents of the window. The "Graphics" menu
- -- allows the user to create a platinum rectangle and rotate a text shape ("QD GX")
- -- from the lower left corner 45 degrees. The font used within the text shape
- -- is the "Skia" font. This font contains font variation information. This information
- -- allows us to change the various axes within the font to receive different
- -- effects. In our case, we retrieve information regarding the 'wght' axis of the
- -- font and set it to the maximum width allowed. By setting the 'wght' axis to the
- -- maximum, we receive nice fat letters. Each letter of the text shape is colored
- -- in a different CMYK color. We will also outline each character in black. Finally,
- -- we add a star pattern to the "X".
- --
- -- As each letter is drawn, you can see the "gxAndMode" transfer mode applied as
- -- the characters overlap.
- --
- -- The second menu "Typography", creates and manipulates a layout shape. The first
- -- menu item will create the layout shape. Once you have created the layout shape,
- -- you will recieve the "as" ligature in "Nasty", swashes for the "C", "N", and "D",
- -- the final form of "e" in "Dude", and the automatic kerning of "WAVE".
- --
- -- For all of the layout effects to work, you need the following fonts installed into
- -- your system:
- --
- -- • Hoefler (this font will be automatically installed, if you use the Installer Script)
- -- • Skia
- -- • HonMincho
- -- • Times
- --
- -- All of the fonts listed above (except Hoefler), can be found in the "Testing Fonts"
- -- Folder contained within the "• Open Me First! •" folder. If these fonts are _not_
- -- installed, you will recieve font substitution, and you will receive interesting
- -- characters when the Kanji text is drawn.
- --
- -- The next item allows you to add two-byte Kanji text to the layout shape. The last
- -- item allows you to perspect the layout shape.
- --
- --
- -- Components: Getting Started GX - main.c
- -- Getting Started GX - main.h
- -- Getting Started GX - shapes.c
- -- Getting Started GX - printing.c
- -- Getting Started GX - misc.c
- -- Getting Started QD GX.π.rsrc
- --
- -- The file titled: "Getting Started GX - main.c" contains the code required
- -- to intialize and tear down the QuickDraw GX world, and the event loop.
- --
- -- The file titled: "Getting Started GX - printing.c" contains the code required
- -- to print the contents of the window.
- --
- -- History: 4/93 New PLA
- -- 12/93 Updated to use the new/changed line layout feature constants with QD GX ß3 PLA
- --
- -- QuickDraw GX
- -- Libraries
- -- Used: This application uses the following QuickDraw GX library code files:
- -- "ColorLibrary.c", "FontLibrary.c", "GraphicsDebugLibrary.c", "LayoutLibrary.c",
- -- "ShapeLibrary.c", "TransferModeLibrary.c", and "TransformLibrary.c".
- --
- --
- -- Notes: 1) Print this file in landscape for the best results
- -- 2) If you are using THINK C v6.x, I have added THINK markers to navigate the code.
- -- 3) This code was adapted from the "Banana Jr." QuickDraw GX sample.
- --
- --
- -- Author: Pete "Luke" Alexander
- -- Developer Technical Support
- -- AppleLink: DEVSUPPORT
- --
- --
- -- ©1992 - 1996 Apple Computer, Inc.
- -- All rights reserved.
- --
- **/
-
-
- #include <events.h>
- #include <memory.h>
- #include <windows.h>
-
- #include "FontLibrary.h"
- #include "GraphicsLibraries.h"
- #include <GXEnvironment.h>
- #include <GXErrors.h>
- #include "QDLibrary.h"
- #include <GXPrinting.h>
- #include <LayoutFeatureConstants.h>
-
- #include "Getting Started GX - main.h"
-
- #include "LayoutLibrary.h"
- #include <GXLayout.h>
-
- //
- // Set up the title and size of the window
- //
- Str255 gWindowTitle = "\p Various Shapes...";
- Rect gWindowQDRect = {50, 10, 470, 590};
-
-
- //
- // If gDebugging = TRUE, graphics library errors and notices will be posted. This functionality will only work with
- // the "debugging" version of the QuickDraw GX init. If this version of the init is not installed, nothing bad will happen,
- // but these functions will not work.
- //
- Boolean gDebugging = true;
-
- //
- // Set "gGiveMeValidation" to TRUE, if you will receive run-time validation.
- //
- Boolean gGiveMeValidation = true;
-
-
- //
- // gGraphicsHeapSize sets the size of the graphics heap created by calling the GXNewGraphicsClient routine
- // in main () within the Getting Started GX - main.c file. You can determine the amount of graphics heap
- // required by using GraphicsBug.I'm giving it 500K, since we need a bunch if we have several windows open.
- //
- long gGraphicsHeapSize = 500;
-
- gxFont gtheSkiaFont;
-
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
- //
- // In this function we create and gxInitialize the the private document structure for a new window. This
- // structure contains the print job and the shape which is drawn in the window. We store this data in
- // a handle and hang it off the window's refCon field for easy retrieval. By doing this, rather than using
- // globals, we can create many windows containing unique print jobs and shapes.
- //
- OSErr DoInitialization(wind)
- WindowPtr wind;
- {
- OSErr err;
- gxJob docJob;
- gxShape docPage;
- TH_Doc windDoc;
-
- //
- // Create the page shape. We set the unique items attribute to make sure that each item added to the
- // picture has a unique reference.
- //
- docPage = GXNewShape(gxPictureType);
- GXSetShapeAttributes(docPage, GXGetShapeAttributes(docPage)|gxUniqueItemsShape);
-
- //
- // Create a print job for this document. This will be the same as the system default until the user
- // goes through the dialogs for Page Setup or Print…
- //
- err = GXNewJob(&docJob);
-
- //
- // If there are no errors, create a handle the size of our document structure and store the print job and page shape
- // in it. Store the handle in the window's refCon field so that we can get at it. (Note that the utility routines
- // "GetDocJob" and "GetDocShape" can be used to do this easily.
- //
- if (!err)
- {
- windDoc = (TH_Doc) NewHandleClear(sizeof(T_Doc));
-
- if (!windDoc)
- err = MemError();
- else
- {
- (*windDoc)->docJob = docJob;
- (*windDoc)->docPage = docPage;
- ((WindowPeek) wind)->refCon = (long) windDoc;
- }
-
- //
- // If there are no errors, install our override for gxPrintingEvent (which will
- // allow us to update our windows as the printing dialogs are moved around.
- //
- GXInstallApplicationOverride(docJob, gxPrintingEventMsg, NewGXPrintingEventProc(MyPrintingEventOverride));
- }
- }
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
- //
- // We retrieve the GX picture attached the window and draw the contents of the window.
- //
- void DoDraw(wind)
- WindowPtr wind;
- {
- GXDrawShape (GetDocShape(wind));
- }
-
-
-
- /*------ CreateNewLayoutShape -------------------------------------------------------------------------*/
- //
- // We create a layout shape and added it ot the GX picture attached to the front window.
- //
-
- void CreateNewLayoutShape(WindowPtr wind)
- {
- gxShape thePage;
- char *sampleText = "Catch the Nasty WAVE, Dude";
- gxShape tempLayoutShape;
- gxPoint layoutPostion = {ff(10), ff(65)};
- gxRunControls runControls;
- gxRunFeature runFeatures[3];
- gxStyle styles[3];
- short totalLengthOfLayout,
- lengthsArray[3],
- loop;
-
- //
- // Retreive the GX picture attached to the front window.
- //
- thePage = GetDocShape(wind);
-
- //
- // We start by intializing the layout run controls to their default values.
- //
- InitializeRunControls(&runControls);
-
-
- //
- // We need to create the style which will be used for the first run of text within our
- // layout shape: "Catch the Nasty WAVE, Dude". Within a layout shape, you have the ability to have
- // multiple runs of text. Each run can use: a different font, text size, run features,
- // run controls.
- //
- // In the case of our first run of text, we want to use Hoefler Italic and a text size of 36.
- // We set the run controls to their default setting.
- //
- styles[0] = NewLayoutStyle((char *)"\pHoefler Italic", ff(36), 0, &runControls, nil, 0, nil);
-
-
- //
- // Next, we want to turn on a couple of run features within this run of text. We start by
- // enabling the "as" ligature in "Nasty". We tell gxLine layout that we want to set the
- // featureType of our run control to enable the ligature capabilities of Hoefler Italic, and
- // we then enable the "as" ligature.
- //
- runFeatures[0].featureType = ligatureType;
- runFeatures[0].featureSelector = ligatureRareOnSelector;
-
-
- //
- // !! •• ß3 Change •• !!
- //
- // The next thing we need to tell line layout to do is enable the swash capabilities of our
- // "C" and "N" characters contained within the first run of text. These swashes are part of the
- // Hoefler Italic font. We acheive this goal by setting the runFeatures featureType
- // to characterAlternativesType with a featureSelector of 1.
- //
- // This is an example were the characterAlternativesType feature is font dependent. Each TrueType
- // GX font can contain 0 or more additional character alternatives selectors defined by a font.
- // In the case of the Hoefler Italic font, the 1st feature enables the "C" and "N" swashes of
- // each word.
- //
- runFeatures[1].featureType = characterAlternativesType;
- runFeatures[1].featureSelector = 1;
-
- //
- // After we have created the run features we need, we set the run features of our
- // style to use them.
- //
- GXSetStyleRunFeatures(styles[0], 2, runFeatures);
-
- //
- // In the second style we need to create is for the "WAVE!" run. For this run of text,
- // we want the font to be Times Roman, 38 point text size, and use the default run
- // controls. This style will also give us automatic kerning of the run.
- //
- styles[1] = NewLayoutStyle((char *)"\pTimes Roman", ff(38), 0, &runControls, nil, 0, nil);
-
-
- //
- // The final style we need to create is used by the last run of text "dude".
- //
- styles[2] = NewLayoutStyle((char *)"\pHoefler Italic", ff(34), 0, &runControls, nil, 0, nil);
-
- //
- // The run features used for the style reference by the last run of text will
- // enable the final form of "e" in "dude". We enable these smartSwashType feature and
- // turn on the final form of "e".
- //
- runFeatures[2].featureType = smartSwashType;
- runFeatures[2].featureSelector = lineFinalSwashesOnSelector;
-
- //
- // Update the style used for this run of text to use the our run features which
- // enable the final form "e".
- //
- GXSetStyleRunFeatures(styles[2], 3, runFeatures);
-
- //
- // The "lengthsArray" defines the length of each run of text used within our layout shape.
- // In our case, the first run of text is 16 characters, the second run is 4 characters,
- // and the final run is 5 characters.
- //
- lengthsArray[0] = 15; lengthsArray[1] = 6; lengthsArray[2] = 5;
-
- totalLengthOfLayout = 26;
-
- //
- // We now update our layout shape to include our 2 new styles. When our layout shape
- // is drawn, the "C" and "N" swashes, "as" ligature, and the kerning of "WAVE!" will
- // appear.
- //
- tempLayoutShape = GXNewLayout(1, &totalLengthOfLayout, (void *) &sampleText,
- 3, lengthsArray, styles, 0, nil, nil, nil, &layoutPostion);
-
- GXSetPictureParts(thePage, 0, 0, 1, &tempLayoutShape, nil, nil, nil);
- GXDisposeShape(tempLayoutShape);
-
-
- //
- // We can now dispose of our styles because they have been added into our layout shape.
- // They are no longer needed....
- //
- for (loop = 0; loop < 3; loop++)
- GXDisposeStyle(styles[loop]);
-
-
- //
- // Invalidate the window's portRect so that everything gets updated.
- //
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
-
-
- /*------ AddKanjiToLayout -----------------------------------------------------------------------------*/
- //
- // This removes single byte roman version of "WAVE", and replaces it with the two-byte Kanji version.
- //
- void AddKanjiToLayout(WindowPtr wind)
- {
- gxShape thePage;
- gxShape tempLayoutShape;
- gxShape layoutShapeFromPicture;
- gxStyle kanjiStyle;
- char *kanjiSampleText = "îgòQ";
- short lengthsArray[1];
-
- //
- // Retreive the GX picture attached to the front window.
- //
- thePage = GetDocShape(wind);
-
- //
- // Retrieve the layout shape from the picture and make a copy of it.
- //
- GXGetPictureParts(thePage, 1, 1, &layoutShapeFromPicture, nil, nil, nil);
- tempLayoutShape = GXCopyToShape (nil, layoutShapeFromPicture);
-
- //
- // Create a new style which uses the "HonMincho Medium" font and set the encoding. If
- // you do not set the encoding for this style, QD GX will not know how to create
- // the characters passed, thereby using the characters in a different manner than
- // you intended.
- //
- kanjiStyle = NewLayoutStyle((char *)"\pHonMincho Medium", ff(39), 0, nil, nil, 0, nil);
- GXSetStyleEncoding (kanjiStyle, gxMacintoshPlatform, gxJapaneseScript, gxJapaneseLanguage);
-
- //
- // We now insert (i.e. replace the roman characters) the new Kanji characters on top
- // of the roman "WAVE". We know the roman characters start at byte location 16 and
- // end at 21.
- //
- lengthsArray[0] = 4;
-
- GXSetLayoutParts(tempLayoutShape, 16, 21, 1, lengthsArray,(void *) &kanjiSampleText,
- 1, lengthsArray, &kanjiStyle, 0, nil, nil);
-
- GXDisposeStyle(kanjiStyle);
-
- //
- // We move our newly modified layout shape and add it to our picture.
- //
- GXMoveShape (tempLayoutShape, 0, ff(75));
- GXValidateShape (tempLayoutShape);
-
- GXSetPictureParts(thePage, 2, 0, 1, &tempLayoutShape, nil, nil, nil);
- GXDisposeShape(tempLayoutShape);
-
-
- //
- // Invalidate the window's portRect so that everything gets updated.
- //
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
- /*------ PerspectLayout -------------------------------------------------------------------------------*/
- //
- // Since a layout shape is treated like any other graphics shape, we can perspect it and preserve
- // all of the layout features when enabled when we created the shape, therefore this function will
- // perspect the current layout shape.
- //
- void PerspectLayout(WindowPtr wind)
- {
- gxShape thePage;
- gxShape tempLayoutShape;
- gxShape layoutShapeFromPicture;
- gxRectangle layoutBounds;
- gxMapping layoutMapping;
- Fixed x, y;
-
- //
- // Retreive the GX picture attached to the front window.
- //
- thePage = GetDocShape(wind);
-
- //
- // Retrieve the layout shape from the picture and make a copy of it.
- //
- GXGetPictureParts(thePage, 2, 1, &layoutShapeFromPicture, nil, nil, nil);
- tempLayoutShape = GXCopyToShape (nil, layoutShapeFromPicture);
-
- //
- // Determine the center of our layout shape.
- //
- GXGetShapeBounds(tempLayoutShape, 0L, &layoutBounds);
- x = layoutBounds.left + layoutBounds.right >> 1;
- y = layoutBounds.top + layoutBounds.bottom >> 1;
-
- //
- // We scale the layout to enable us to get a better visual effect when we prespect it,
- // and we move it to prevent it fonr drawing on top of the latest layout shape added
- // to the picture.
- //
- GXScaleShape(tempLayoutShape, ff(2), ff(2), 0, 0);
- GXMoveShape(tempLayoutShape, 0, ff(100));
-
- //
- // Retrieve the gxMapping of our layout shape and perspect it, pulling along and
- // down the x-axis.
- //
- GXGetShapeMapping(tempLayoutShape, &layoutMapping);
- layoutMapping.map[0][2] = ff(30);
- layoutMapping.map[1][2] = ff(1);
- GXSetShapeMapping(tempLayoutShape, &layoutMapping);
-
- //
- // Add our newly perspected layout shape to our picture.
- //
- GXSetPictureParts(thePage, 3, 0, 1, &tempLayoutShape, nil, nil, nil);
- GXDisposeShape(tempLayoutShape);
-
-
- //
- // Invalidate the window's portRect so that everything gets updated.
- //
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
- /*------ CreateABlackRectangle ------------------------------------------------------------------------*/
- //
- // We want to create a black rectangle. Within GX, you need to define the geometry and create a shape.
- // You are then ready to draw the particular shape.
- //
- void CreateABlackRectangle (WindowPtr wind)
- {
- gxShape thePage;
- gxShape tempRectShape;
- gxRectangle rectGeometry = {ff(70), ff(70), ff(280), ff(275)};
-
- //
- // Retreive the GX picture attached to the front window.
- //
- thePage = GetDocShape(wind);
-
- //
- // Create the rectangle which is defined by the rectangular geometry contained within
- // "rectGeometry" and add it to our picture.
- //
- tempRectShape = GXNewRectangle(&rectGeometry);
- GXSetPictureParts(thePage, 0, 0, 1, &tempRectShape, nil, nil, nil);
- GXDisposeShape(tempRectShape);
-
- //
- // Invalidate the window's portRect so that everything gets updated.
- //
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
- /*------ ColorTheRectangle ----------------------------------------------------------------------------*/
- //
- // We want to color our rectangle a more interesting color to allow the transfer modes we will add to
- // the text shape to appear, therefore we color our rectangle "platinum". We use the common color
- // library to perform the coloring. In this case, the library creates the platinum color in RGB space.
- //
- void ColorTheRectangle (WindowPtr wind)
- {
- gxShape thePage;
- gxShape tempRectShape;
-
- //
- // Retreive the GX picture attached to the front window.
- //
- thePage = GetDocShape(wind);
-
- //
- // Get a reference to our black rectangle and change the color to platinum.
- //
- GXGetPictureParts(thePage, 1, 1, &tempRectShape, nil, nil, nil);
- SetShapeCommonColor (tempRectShape, platinum );
-
-
- //
- // Invalidate the window's portRect so that everything gets updated.
- //
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
-
- /*------ CreateAQ -------------------------------------------------------------------------------------*/
- //
- // We want to create the first text shape - "Q". So, we need to create the following GX objects:
- // the text shape containing the "Q", the CMYK color used to color "Q", a style which defines the
- // font, font size, the 'wght', pen width, and pen drawing location.
- //
- void CreateAQ (WindowPtr wind)
- {
- gxShape thePage;
- gxShape tempTextShape;
- Fixed maxVariationValue;
- gxFontVariation fontVariation;
- long result;
-
- //
- // Retreive the GX picture attached to the front window.
- //
- thePage = GetDocShape(wind);
-
- //
- // Create a new style to contain: the font, font size, the 'wght' axis of the font set to the
- // maximum value allowed for this font, set the pen size, and the location of the pen when
- // drawing.
- //
- gOurStyle = GXNewStyle ();
-
- GXSetStylePen(gOurStyle, ff(2));
- GXSetStyleAttributes(gOurStyle, gxOutsideFrameStyle);
-
- GXSetStyleTextSize(gOurStyle, ff(135));
- gtheSkiaFont = FindPNameFont (gxFullFontName, "\pSkia Regular");
- GXSetStyleFont(gOurStyle, gtheSkiaFont);
-
- result = GXFindFontVariation(gtheSkiaFont, 'wght', nil, nil, &maxVariationValue, nil);
-
- //
- // If the "result" is good, we proceed to set the "wght" axis to the maximum value. If the
- // "result" is bad, this probably means that the "Skia" font has not been installed. In this
- // case we cannot set the "wght" axis, so we do not and we alert the user. We will be able
- // to continue at this gxPoint, but we will not have the fat juicy letters.
- //
- if (result) {
- fontVariation.name = 'wght';
- fontVariation.value = maxVariationValue;
-
- GXSetStyleFontVariations(gOurStyle, 1, &fontVariation);
-
- } else DebugStr ("\p NO 'wght' axis....");
-
- //
- // Set up as CMYK color space which will used to color all of our text shapes. The "Q" will
- // be colored in magenta. Each text shape will use a different CMYK color. We change the setting
- // for our "gTextColor" when we create each new shape.
- //
- gTextColor.space = gxCMYKSpace;
- gTextColor.element.cmyk.cyan = 0x0000;
- gTextColor.element.cmyk.magenta = 0xffff;
- gTextColor.element.cmyk.yellow = 0x0000;
- gTextColor.element.cmyk.black = 0x0000;
- gTextColor.profile = nil;
-
- //
- // Create the "Q", and set it's: style, transfer mode, color, and shape fill.
- //
- tempTextShape = GXNewText (1, (unsigned char*) "Q", &gTextLocation);
- SetShapeCommonTransfer(tempTextShape, gxAndMode);
- GXSetShapeStyle(tempTextShape, gOurStyle);
- GXSetShapeColor(tempTextShape, &gTextColor);
-
- gRotatedTransform = GXNewTransform ();
- GXRotateTransform(gRotatedTransform, -ff(40), ff(200), ff(200));
- GXMoveTransform(gRotatedTransform, ff(40), ff(100));
-
- GXSetPictureParts(thePage, 0, 0, 1, &tempTextShape, nil, nil, &gRotatedTransform);
- GXDisposeShape(tempTextShape);
-
- //
- // Invalidate the window's portRect so that everything gets updated.
- //
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
- /*------ OutlineTheQ ----------------------------------------------------------------------------------*/
- //
- // We want to outline our "Q" in black. So, we retrieve a copy of the "Q" from our picture, make
- // a copy, change the shape fill to outline, color the outline back, and add the copy to our picture.
- //
- void OutlineTheQ (WindowPtr wind)
- {
- gxShape thePage;
- gxShape tempTextShape;
- gxShape theQFromThePicture;
-
- //
- // Retreive the GX picture attached to the front window.
- //
- thePage = GetDocShape(wind);
-
- //
- // Retrieve the "Q" from our picture and make a copy.
- //
- GXGetPictureParts(thePage, 2, 1, &theQFromThePicture, nil, nil, nil);
- tempTextShape = GXCopyToShape (nil, theQFromThePicture);
-
- //
- // Set the shape fill to be outline of our "Q", center the pen on the geometry,
- // and color it black.
- //
- GXSetShapeType(tempTextShape, gxPathType);
- GXSetShapeFill(tempTextShape, gxClosedFrameFill);
- GXSetShapeStyleAttributes(tempTextShape, gxCenterFrameStyle);
- SetShapeCommonColor(tempTextShape, gxBlack);
- SetShapeCommonTransfer(tempTextShape, gxCopyMode);
-
- //
- // Add the new outlined "Q" to our picture.
- //
- GXSetPictureParts(thePage, 3, 0, 1, &tempTextShape, nil, nil, nil);
- GXDisposeShape(tempTextShape);
-
- //
- // Invalidate the window's portRect so that everything gets updated.
- //
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
- /*------ CreateAD -------------------------------------------------------------------------------------*/
- //
- // We want to add a "D" to our picture, which is colored a yellow CMYK color, and outline it.
- //
- void CreateAD (WindowPtr wind)
- {
- gxShape thePage;
- gxShape tempTextShape;
-
- //
- // Retreive the GX picture attached to the front window.
- //
- thePage = GetDocShape(wind);
-
- //
- // Set the CYMK color to be yellow.
- //
- gTextColor.element.cmyk.magenta = 0x0000;
- gTextColor.element.cmyk.yellow = 0xffff;
-
- //
- // Create the "D", set it's transfer mode to gxAndMode with the transfer mode library,
- // and set it's starting location, set the color, attach the style, and set the shape fill.
- //
- gTextLocation.x += ff(75);
- tempTextShape = GXNewText (1, (unsigned char*) "D", &gTextLocation);
- SetShapeCommonTransfer(tempTextShape, gxAndMode);
- GXSetShapeStyle(tempTextShape, gOurStyle);
- GXSetShapeColor(tempTextShape, &gTextColor);
-
- GXSetPictureParts(thePage, 0, 0, 1, &tempTextShape, nil, nil, &gRotatedTransform);
-
- //
- // Create the outline of the "D", center the pen on the geometry of the outline,
- // color it black and add it to the picture.
- //
- GXSetShapeType(tempTextShape, gxPathType);
- GXSetShapeStyleAttributes(tempTextShape, gxCenterFrameStyle);
- GXSetShapeFill(tempTextShape, gxClosedFrameFill);
- SetShapeCommonColor(tempTextShape, gxBlack);
- SetShapeCommonTransfer(tempTextShape, gxCopyMode);
-
- GXSetPictureParts(thePage, 0, 0, 1, &tempTextShape, nil, nil, &gRotatedTransform);
- GXDisposeShape(tempTextShape);
-
- //
- // Invalidate the window's portRect so that everything gets updated.
- //
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
-
- /*------ CreateAG -------------------------------------------------------------------------------------*/
- //
- // We want to add a "G" to our picture, which is colored a yellow CMYK color, and outline it.
- //
- void CreateAG (WindowPtr wind)
- {
- gxShape thePage;
- gxShape tempTextShape;
-
- //
- // Retreive the GX picture attached to the front window.
- //
- thePage = GetDocShape(wind);
-
- //
- // Set the CYMK color to be yellow.
- //
- gTextColor.element.cmyk.cyan = 0xffff;
- gTextColor.element.cmyk.yellow = 0x0000;
-
- //
- // Create the "G", set it's transfer mode to gxAndMode with the transfer mode library,
- // and set it's starting location, set the color, attach the style, and set the shape fill.
- //
- gTextLocation.x += ff(75);
- tempTextShape = GXNewText (1, (unsigned char*) "G", &gTextLocation);
- SetShapeCommonTransfer(tempTextShape, gxAndMode);
- GXSetShapeStyle(tempTextShape, gOurStyle);
- GXSetShapeColor(tempTextShape, &gTextColor);
-
- GXSetShapeType(tempTextShape, gxPathType);
- GXSetPictureParts(thePage, 0, 0, 1, &tempTextShape, nil, nil, &gRotatedTransform);
-
- //
- // Create the outline of the "G" and add it to the picture.
- //
- GXSetShapeStyleAttributes(tempTextShape, gxCenterFrameStyle);
- GXSetShapeFill (tempTextShape, gxClosedFrameFill);
- SetShapeCommonColor (tempTextShape, gxBlack );
- SetShapeCommonTransfer(tempTextShape, gxCopyMode);
-
- GXSetPictureParts(thePage, 0, 0, 1, &tempTextShape, nil, nil, &gRotatedTransform);
- GXDisposeShape(tempTextShape);
-
-
- //
- // Invalidate the window's portRect so that everything gets updated.
- //
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
-
- /*------ CreateAX -------------------------------------------------------------------------------------*/
- //
- // We create our "X", outline it, and fill it with stars.
- //
- void CreateAX (WindowPtr wind)
- {
- gxShape thePage;
- gxShape tempTextShape;
- gxShape starShape;
- gxRectangle starShapeBounds;
- gxPatternRecord starPattern;
-
- long starGeometry[] = { 1, // number of contours
- 5, // number of points
- ff(60), 0, ff(90), ff(90), ff(0), ff(30), ff(120), ff(30), ff(0), ff(90)}; // the points
-
- //
- // Retrieve the GX picture attached to the front window.
- //
- thePage = GetDocShape(wind);
-
- //
- // Create a star shape which will be used as the fill pattern
- //
- starShape = GXNewPolygons((gxPolygons *) starGeometry);
- GXSetShapeFill (starShape, gxWindingFill);
- GXScaleShape(starShape, fl(0.15), fl(0.15), 0, 0);
-
- //
- // Get the bounds of our star shape. We use the bounds to setup the u and v vectors of the pattern
- // record. We want "tempTextShape" to be filled with the star where each star is placed at edge of the
- // previous star (i.e so the pattern's do not overlap).
- //
- // We set up the pattern record to use our star shape and no attributes will be used when the filled
- // shape is drawn.
- //
- GXGetShapeBounds(starShape, 0L, &starShapeBounds);
-
- starPattern.u.x = 0;
- starPattern.u.y = starShapeBounds.bottom;
- starPattern.v.x = starShapeBounds.right + fixed1;
- starPattern.v.y = 0;
-
- starPattern.attributes = gxNoAttributes;
- starPattern.pattern = starShape;
-
- //
- // Set the CYMK color to be magenta.
- //
- gTextColor.element.cmyk.cyan = 0x0000;
- gTextColor.element.cmyk.magenta = 0xffff;
-
- gTextLocation.x += ff(65);
-
- //
- // Create our "X", set the transfer mode to AndMode using the transfer mode library, set the
- // style, shape fill, shape type, and add the rotated transform.
- //
- // We need to set our shape type to be path, which will allow us to fill it with stars. You can
- // only fill a shape which is a geometric shape type (i.e. you cannot fill a text shape). Also,
- // when you are filling a shape, it fills to the boundary of the geometry for the shape fill
- // specified.
- //
- // The first "X" we add to the picture will be the outline of the "X", without the star shapew
- // fill.
- tempTextShape = GXNewText (1, (unsigned char*) "X", &gTextLocation);
-
- SetShapeCommonTransfer(tempTextShape, gxCopyMode);
- GXSetShapeStyle(tempTextShape, gOurStyle);
- GXSetShapeType (tempTextShape, gxPathType);
- GXSetShapeFill (tempTextShape, gxClosedFrameFill);
- GXSetShapeTransform(tempTextShape, gRotatedTransform);
-
- GXSetPictureParts(thePage, 0, 0, 1, &tempTextShape, nil, nil, &gRotatedTransform);
-
- //
- // Set the color for the "X", set the fill to be solid, and attach the pattern record to
- // our shape. By attaching the pattern record to our shape, adds a unique style to our
- // shape which contains the pattern record.
- //
- SetShapeCommonTransfer(tempTextShape, gxAndMode);
- GXSetShapeColor(tempTextShape, &gTextColor);
- GXSetShapeFill (tempTextShape, gxSolidFill);
- GXSetShapePattern(tempTextShape, &starPattern);
- GXDisposeShape(starShape);
-
- GXSetPictureParts(thePage, 0, 0, 1, &tempTextShape, nil, nil, &gRotatedTransform);
- GXDisposeShape(tempTextShape);
-
- //
- // Invalidate the window's portRect so that everything gets updated.
- //
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
-
- /*------ DoCreateNew ---------------------------------------------------------------------------------*/
- //
- // This routine is called when a window needs to be created. We create a window and add a QuickDraw GX
- // gxViewPort to allow all of the QuickDraw GX drawing to occur in the correct window.
- //
- OSErr DoCreateNew(void)
- {
- OSErr err;
- WindowPtr wind;
-
- //
- // Create a window, attach a default gxViewPort to it, create and gxInitialize our privat data
- // for it, and add a sample image to its page shape.
- //
-
- wind = NewWindow(nil, &gWindowQDRect, gWindowTitle, true, noGrowDocProc, (WindowPtr)-1L, true, 0L);
-
- if (!wind)
- err = MemError();
- else
- {
- GXIgnoreGraphicsNotice(transform_already_set);
- SetDefaultViewPort(GXNewWindowViewPort(wind));
- GXPopGraphicsNotice();
- err = DoInitialization(wind);
- }
-
- return err;
- }
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
- //
- // This routine is called when a window needs to be disposed of.
- //
- void DoDispose(wind)
- WindowPtr wind;
- {
- TH_Doc doc;
-
- /**
- You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- can turn notices on in this file by setting gDebugging = TRUE (above).
- **/
-
- doc = (TH_Doc) GetWRefCon(wind); // Remember, this is where we stored our private data.
-
- GXDisposeShape(GetDocShape(wind)); // Dispose of this doc's shape.
- GXDisposeJob(GetDocJob(wind)); // Dispose of this doc's print job.
- DisposHandle((Handle) doc); // Dispose of our private data.
-
- DisposeWindow(wind); // Dispose of the window.
- }
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
- //
- // This routine is called to do things while we're idling through tthe event loop.
- //
- void DoIdle(WindowPtr wind)
- {
- }
-
-